package com.china08.yxyapi.api.home.activity.weike;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.huodong.YxyHuodongWeikeContest;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyHuodongWeikeContestRepository;
import com.china08.yxyapi.security.profile.YxyProfile;

@CrossOrigin
@RestController
public class ActivityUserInfoController extends YxyApiBaseController {

    @Autowired
    private YxyHuodongWeikeContestRepository yxyHuodongWeikeContestRepository;

    @RequestMapping(value = "/api_yw/home/activity/tea/user/detail", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(@RequestBody ReqModel model, HttpServletRequest request, HttpServletResponse response) {
        YxyProfile profile = getProfile(request, response);
        RespModel respModel = new RespModel();
        YxyHuodongWeikeContest weikeContest = yxyHuodongWeikeContestRepository.findByUserId(profile.getId());
        if (weikeContest != null) {
            if (!weikeContest.getSchoolid().equals(profile.getSchoolId())) {
                respModel.statusUser = 1;
                respModel.sid = weikeContest.getSchoolid();
                respModel.sname = weikeContest.getSchoolNick();
            } else {
                respModel.statusUser = 1;
                respModel.sid = weikeContest.getSchoolid();
                respModel.sname = weikeContest.getSchoolNick();
            }
        }
        return respModel;
    }

    protected static class ReqModel extends YxyApiReqModel {
    }

    protected static class RespModel extends YxyApiRespModel {
        public Integer statusUser = 0;
        public String sid;
        public String sname;
    }
}
